from flask import Blueprint, g, redirect, url_for, request

# 创建蓝图，并设置蓝图前缀 url_prefix="/admin"
from info import user_is_login

admin_blue = Blueprint('admin',__name__,url_prefix='/admin')

from . import view


@admin_blue.before_request
@user_is_login
def user_is_admin():
    user = g.user
    if not request.url.endswith(url_for("admin.admin_login")):
        if not user:
            return  redirect(url_for('admin.admin_login'))
        elif not user.is_admin:
            return  redirect(url_for('index.index'))

